package com.aidex.biz.controller;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.TaizhangModel;
import com.aidex.biz.service.TaizhangModelService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 台账模版Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/biz/bizTaizhangModel")
public class TaizhangModelController extends BaseController
{
    @Autowired
    private TaizhangModelService taizhangModelService;

    /**
     * 查询台账模版列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhangModel:list')")
    @GetMapping("/list")
    public R<PageInfo> list(TaizhangModel taizhangModel, HttpServletRequest request, HttpServletResponse response)
    {
        if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                taizhangModel.setCompanyId(null);
        }else{
                     taizhangModel.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                 }
        taizhangModel.setPage(new PageDomain(request, response));
        return R.data(taizhangModelService.findPage(taizhangModel));
    }

    /**
     * 获取台账模版详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhangModel:query')")
    @GetMapping(value = "/{id}")
    public R<TaizhangModel> detail(@PathVariable("id") String id)
    {
        return R.data(taizhangModelService.get(id));
    }

    /**
     * 新增台账模版
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhangModel:add')")
    @Log(title = "台账模版", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  TaizhangModel taizhangModel)
    {
        return R.status(taizhangModelService.save(taizhangModel));
    }

    /**
     * 修改台账模版
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhangModel:edit')")
    @Log(title = "台账模版", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated TaizhangModel taizhangModel)
    {
        return R.status(taizhangModelService.save(taizhangModel));
    }


    /**
     * 删除台账模版
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhangModel:remove')")
    @Log(title = "台账模版", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(taizhangModelService.deleteTaizhangModelByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhangModel:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(taizhangModelService.findMaxSort(new TaizhangModel()));
    }

    /**
     * 导出台账模版列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizTaizhangModel:export')")
    @Log(title = "台账模版", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(TaizhangModel taizhangModel)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    taizhangModel.setCompanyId(null);
            }else{
                         taizhangModel.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<TaizhangModel> list = taizhangModelService.findList(taizhangModel);
        ExcelUtil<TaizhangModel> util = new ExcelUtil<TaizhangModel>(TaizhangModel.class);
        return util.exportExcel(list, "台账模版数据");
    }

}
